package main

import "github.com/kataras/iris"

type ResponseCode int

const (
	OK 		ResponseCode = 200

	// 交易对不存在
	ERR_PARAMETER				= 1000
	ERR_COINPAIR_NOT_EXISTS 	= 1001
	ERR_CTL_TYPE 				= 1002
	ERR_COINPAIR_NOT_ENABLE 	= 1003
)

var ResponseMessage = map[ResponseCode]string{
	200: 			"success",

	1000: 			"parameter error",
	1001: 			"coin pair not found",
	1002: 			"the control type not supported",
	1003: 			"coin pair status not enabled",
}

func (self ResponseCode) Enum() int {
	return int(self)
}

func (self ResponseCode) String() string {
	if msg, ok := ResponseMessage[self]; ok {
		return msg
	}
	return ""
}

func ApiSuccess(ctx iris.Context, data interface{}) {
	ctx.JSON(map[string]interface{}{
		"code": 	OK.Enum(),
		"msg":		OK.String(),
		"data": 	data,
	})
}

func ApiError(ctx iris.Context, code ResponseCode) {
	ctx.JSON(map[string]interface{}{
		"code": 	code.Enum(),
		"msg": 		code.String(),
	})
}